<!-- 其他人的个人信息 -->
<template>
  <div class="others-container">
    <van-nav-bar :left-arrow="true"
                 @click-left="onClickLeft"> </van-nav-bar>

    <van-row class="user-row-style">
      <van-col span="6">
        <van-image round
                   class="avater-style"
                   width="2rem"
                   height="2rem"
                   :src="fromUserInfo.avatar" />
      </van-col>
      <van-col span="16">
        <van-config-provider :theme-vars="themeVars">
          <van-cell center
                    :label="'id:'+fromUserInfo.id"
                    :value="fromUserInfo.motto">
            <template #title>
              <span>{{fromUserInfo.realName}}</span>
              <van-icon name="https://b.yzcdn.cn/vant/icon-demo-1126.png" />
            </template>
          </van-cell>
        </van-config-provider>
      </van-col>
    </van-row>

    <div class="setting-style">
      <van-cell is-link
                center
                class="top-cell"
                clickable>
        <!-- 使用 title 插槽来自定义标题 -->
        <template #title>
          <van-icon name="shrink" />
          <span class="custom-title">圈子</span>
        </template>
      </van-cell>
    </div>

    <div class="setting-style">
      <van-cell class="top-cell-end"
                clickable
                style="text-align:center">
        <!-- 使用 title 插槽来自定义标题 -->
        <template #title>
          <van-icon name="chat-o" />
          <span class="custom-title"
                @click="sendMessage">发送消息</span>
        </template>
      </van-cell>
      <van-cell center
                class="top-cell-end"
                clickable>
        <!-- 使用 title 插槽来自定义标题 -->
        <template #title>
          <van-icon name="phone-o" />
          <span class="custom-title"
                @click="sendAudio">发送音视频</span>
        </template>
      </van-cell>
    </div>

  </div>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';

export default {
  //import引入的组件需要注入到对象中才能使用
  components: {},
  data () {
    //这里存放数据
    return {
      themeVars: { cellLabelMarginTop: "0.3rem" },
      // 对方的用户基本信息，用户名，头像，座右铭等
      fromUserInfo: {},
      fromIdentity: '',
    };
  },
  //方法集合
  methods: {
    init () {
      var that = this;
      // 获取用户基础信息
      that.$http
        .get(that.$reqPrefix.user + "/users/" + that.fromIdentity, {}).then(res => {
          that.fromUserInfo = res.data;
        }).catch(err => {
          Toast.fail(err.data.message);
        });
    },
    onClickLeft () {
      this.$router.replace({ name: "UserChat", params: { identity: this.fromIdentity } });
    },
    // 给对方发送消息
    sendMessage () {
      var that = this;
      // 调用接口，初始化一条数据到用户聊天框中
      that.$http
        .post(that.$reqPrefix.user + "/im/users/add-chat", {
          'bindUserIdentity': this.fromIdentity
        }, null).then(res => {
          that.fromUserInfo = res.data;
        }).catch(err => {
          Toast.fail(err.data.message);
        });
      // 跳转到发消息页面，携带对方的id
      this.$router.replace({ name: "UserChat", params: { 'identity': this.fromIdentity } });
    },
    // 给对方发送音视频
    sendAudio () {
      this.$toast("暂未开放！");
    },
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //生命周期 - 创建完成（可以访问当前this实例）
  created () {
    this.fromIdentity = this.$route.params.identity;
    this.init();
  },
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted () { },
  //生命周期 - 创建之前
  beforeCreate () { },
  //生命周期 - 挂载之前
  beforeMount () { },
  //生命周期 - 更新之前
  beforeUpdate () { },
  //生命周期 - 更新之后
  updated () { },
  //生命周期 - 销毁之前
  beforeUnmount () { },
  //生命周期 - 销毁完成
  unmounted () { },
  //如果页面有keep-alive缓存功能，这个函数会触发
  activated () { },
};
</script>
<style lang="less" scoped>
//@import url(); 引入公共css类
.others-container {
  position: absolute;
  height: 100%;
  width: 100%;
  background: whitesmoke;
}
.avater-style {
  margin-left: 16px;
}
.user-row-style {
  border-bottom: 1px solid #f7f8fa;
  background-color: #ffffff;
}
.top-cell /deep/ .van-cell__title {
  display: flex;
  align-items: center;
}
.top-cell-end /deep/ .van-cell__title {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #0000cc;
}
.setting-style {
  margin-top: 0.3rem;
}
.custom-title {
  display: inline-flex;
  align-items: center;
  height: 100%;
  margin-left: 10px;
}
.meeting-btn-container {
  display: flex;
  justify-content: space-around;
}
.meeting-btn {
  margin-top: 40px;
  width: 300px;
}
</style>
